
import itertools
import PokerTools
import TexasHoldem

handEval = TexasHoldem.HandEval()
#************************************************************************************
#
#************************************************************************************
NoFlops = 19600
HandNames = {
		'StraightFlush': 0,
		'Quads': 1,
		'FullHouse': 2,
		'Flush': 3,
		'Straight': 4,
		'Set': 5,
		'Trips': 6,
		'TwoPair': 7,
		'Pair': 8,
		'FlushDraw': 9,
		'StraightDraw': 10,
		'InsideStraightDraw': 11,
		'Pair': 12,
		'TopPair': 13,
		'OverPair': 14,
		}
HandNameIds = dict([(b, a) for a, b in HandNames.items()])
HandTypeData = {
	'AA': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:0,11:0,12:0,13:0,14:17248,},
	'AKs': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:0,11:0,12:0,13:5676,14:0,},
	'AKo': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:0,11:0,12:0,13:5676,14:0,},
	'AQs': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:63,11:63,12:498,13:5178,14:0,},
	'AQo': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:64,11:64,12:498,13:5178,14:0,},
	'AJs': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:126,11:63,12:948,13:4728,14:0,},
	'AJo': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:128,11:64,12:948,13:4728,14:0,},
	'ATs': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:189,11:63,12:1350,13:4326,14:0,},
	'ATo': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:192,11:64,12:1350,13:4326,14:0,},
	'A9s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:0,12:1704,13:3972,14:0,},
	'A9o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:0,12:1704,13:3972,14:0,},
	'A8s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:63,12:2010,13:3666,14:0,},
	'A8o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:64,12:2010,13:3666,14:0,},
	'A7s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:63,12:2268,13:3408,14:0,},
	'A7o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:64,12:2268,13:3408,14:0,},
	'A6s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:0,12:2478,13:3198,14:0,},
	'A6o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:0,12:2478,13:3198,14:0,},
	'A5s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:189,11:63,12:2640,13:3036,14:0,},
	'A5o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:192,11:64,12:2640,13:3036,14:0,},
	'A4s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:126,11:63,12:2754,13:2922,14:0,},
	'A4o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:128,11:64,12:2754,13:2922,14:0,},
	'A3s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:63,11:63,12:2820,13:2856,14:0,},
	'A3o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:64,11:64,12:2820,13:2856,14:0,},
	'A2s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:0,11:0,12:2838,13:2838,14:0,},
	'A2o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:0,11:0,12:2838,13:2838,14:0,},
	'KK': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:64,11:0,12:4048,13:0,14:13200,},
	'KQs': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:585,11:0,12:996,13:4680,14:0,},
	'KQo': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:592,11:0,12:996,13:4680,14:0,},
	'KJs': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:648,11:63,12:1446,13:4230,14:0,},
	'KJo': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:656,11:64,12:1446,13:4230,14:0,},
	'KTs': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:711,11:63,12:1848,13:3828,14:0,},
	'KTo': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:720,11:64,12:1848,13:3828,14:0,},
	'K9s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:189,11:63,12:2202,13:3474,14:0,},
	'K9o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:192,11:64,12:2202,13:3474,14:0,},
	'K8s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:2508,13:3168,14:0,},
	'K8o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:2508,13:3168,14:0,},
	'K7s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:63,12:2766,13:2910,14:0,},
	'K7o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:64,12:2766,13:2910,14:0,},
	'K6s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:2976,13:2700,14:0,},
	'K6o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:2976,13:2700,14:0,},
	'K5s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:3138,13:2538,14:0,},
	'K5o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:3138,13:2538,14:0,},
	'K4s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:0,12:3252,13:2424,14:0,},
	'K4o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:0,12:3252,13:2424,14:0,},
	'K3s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:189,11:0,12:3318,13:2358,14:0,},
	'K3o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:192,11:0,12:3318,13:2358,14:0,},
	'K2s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:126,11:0,12:3336,13:2340,14:0,},
	'K2o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:128,11:0,12:3336,13:2340,14:0,},
	'QQ': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:128,11:0,12:7408,13:0,14:9840,},
	'QJs': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1170,11:63,12:1896,13:3780,14:0,},
	'QJo': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1184,11:64,12:1896,13:3780,14:0,},
	'QTs': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1233,11:126,12:2298,13:3378,14:0,},
	'QTo': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1248,11:128,12:2298,13:3378,14:0,},
	'Q9s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:711,11:63,12:2652,13:3024,14:0,},
	'Q9o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:720,11:64,12:2652,13:3024,14:0,},
	'Q8s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:252,11:126,12:2958,13:2718,14:0,},
	'Q8o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:256,11:128,12:2958,13:2718,14:0,},
	'Q7s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:0,12:3216,13:2460,14:0,},
	'Q7o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:0,12:3216,13:2460,14:0,},
	'Q6s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:63,12:3426,13:2250,14:0,},
	'Q6o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:64,12:3426,13:2250,14:0,},
	'Q5s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:0,12:3588,13:2088,14:0,},
	'Q5o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:0,12:3588,13:2088,14:0,},
	'Q4s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:3702,13:1974,14:0,},
	'Q4o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:3702,13:1974,14:0,},
	'Q3s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:0,12:3768,13:1908,14:0,},
	'Q3o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:0,12:3768,13:1908,14:0,},
	'Q2s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:189,11:0,12:3786,13:1890,14:0,},
	'Q2o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:192,11:0,12:3786,13:1890,14:0,},
	'JJ': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:192,11:0,12:10144,13:0,14:7104,},
	'JTs': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:2700,13:2976,14:0,},
	'JTo': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:2700,13:2976,14:0,},
	'J9s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1233,11:126,12:3054,13:2622,14:0,},
	'J9o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1248,11:128,12:3054,13:2622,14:0,},
	'J8s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:774,11:126,12:3360,13:2316,14:0,},
	'J8o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:784,11:128,12:3360,13:2316,14:0,},
	'J7s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:315,11:126,12:3618,13:2058,14:0,},
	'J7o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:320,11:128,12:3618,13:2058,14:0,},
	'J6s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:441,11:0,12:3828,13:1848,14:0,},
	'J6o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:448,11:0,12:3828,13:1848,14:0,},
	'J5s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:441,11:63,12:3990,13:1686,14:0,},
	'J5o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:448,11:64,12:3990,13:1686,14:0,},
	'J4s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:0,12:4104,13:1572,14:0,},
	'J4o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:0,12:4104,13:1572,14:0,},
	'J3s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:4170,13:1506,14:0,},
	'J3o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:4170,13:1506,14:0,},
	'J2s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:252,11:0,12:4188,13:1488,14:0,},
	'J2o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:256,11:0,12:4188,13:1488,14:0,},
	'TT': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:12320,13:0,14:4928,},
	'T9s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:3408,13:2268,14:0,},
	'T9o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:3408,13:2268,14:0,},
	'T8s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1296,11:189,12:3714,13:1962,14:0,},
	'T8o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1312,11:192,12:3714,13:1962,14:0,},
	'T7s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:837,11:126,12:3972,13:1704,14:0,},
	'T7o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:848,11:128,12:3972,13:1704,14:0,},
	'T6s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:378,11:126,12:4182,13:1494,14:0,},
	'T6o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:384,11:128,12:4182,13:1494,14:0,},
	'T5s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:504,11:0,12:4344,13:1332,14:0,},
	'T5o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:512,11:0,12:4344,13:1332,14:0,},
	'T4s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:441,11:63,12:4458,13:1218,14:0,},
	'T4o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:448,11:64,12:4458,13:1218,14:0,},
	'T3s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:0,12:4524,13:1152,14:0,},
	'T3o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:0,12:4524,13:1152,14:0,},
	'T2s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:4542,13:1134,14:0,},
	'T2o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:4542,13:1134,14:0,},
	'99': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:14000,13:0,14:3248,},
	'98s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:4020,13:1656,14:0,},
	'98o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:4020,13:1656,14:0,},
	'97s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1296,11:189,12:4278,13:1398,14:0,},
	'97o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1312,11:192,12:4278,13:1398,14:0,},
	'96s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:837,11:126,12:4488,13:1188,14:0,},
	'96o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:848,11:128,12:4488,13:1188,14:0,},
	'95s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:378,11:126,12:4650,13:1026,14:0,},
	'95o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:384,11:128,12:4650,13:1026,14:0,},
	'94s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:441,11:0,12:4764,13:912,14:0,},
	'94o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:448,11:0,12:4764,13:912,14:0,},
	'93s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:63,12:4830,13:846,14:0,},
	'93o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:64,12:4830,13:846,14:0,},
	'92s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:4848,13:828,14:0,},
	'92o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:4848,13:828,14:0,},
	'88': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:15248,13:0,14:2000,},
	'87s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:4536,13:1140,14:0,},
	'87o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:4536,13:1140,14:0,},
	'86s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1296,11:189,12:4746,13:930,14:0,},
	'86o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1312,11:192,12:4746,13:930,14:0,},
	'85s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:837,11:126,12:4908,13:768,14:0,},
	'85o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:848,11:128,12:4908,13:768,14:0,},
	'84s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:315,11:126,12:5022,13:654,14:0,},
	'84o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:320,11:128,12:5022,13:654,14:0,},
	'83s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:378,11:0,12:5088,13:588,14:0,},
	'83o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:384,11:0,12:5088,13:588,14:0,},
	'82s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:63,12:5106,13:570,14:0,},
	'82o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:64,12:5106,13:570,14:0,},
	'77': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:16128,13:0,14:1120,},
	'76s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:4956,13:720,14:0,},
	'76o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:4956,13:720,14:0,},
	'75s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1296,11:189,12:5118,13:558,14:0,},
	'75o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1312,11:192,12:5118,13:558,14:0,},
	'74s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:774,11:126,12:5232,13:444,14:0,},
	'74o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:784,11:128,12:5232,13:444,14:0,},
	'73s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:252,11:126,12:5298,13:378,14:0,},
	'73o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:256,11:128,12:5298,13:378,14:0,},
	'72s': {0:0,1:2,2:18,3:165,4:0,5:0,6:264,7:396,9:2145,10:315,11:0,12:5316,13:360,14:0,},
	'72o': {0:0,1:2,2:18,3:0,4:0,5:0,6:264,7:396,9:440,10:320,11:0,12:5316,13:360,14:0,},
	'66': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:16704,13:0,14:544,},
	'65s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:5280,13:396,14:0,},
	'65o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:5280,13:396,14:0,},
	'64s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1233,11:126,12:5394,13:282,14:0,},
	'64o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1248,11:128,12:5394,13:282,14:0,},
	'63s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:711,11:63,12:5460,13:216,14:0,},
	'63o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:720,11:64,12:5460,13:216,14:0,},
	'62s': {0:1,1:2,2:18,3:164,4:63,5:0,6:264,7:396,9:2145,10:189,11:63,12:5478,13:198,14:0,},
	'62o': {0:0,1:2,2:18,3:0,4:64,5:0,6:264,7:396,9:440,10:192,11:64,12:5478,13:198,14:0,},
	'55': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:256,11:0,12:17040,13:0,14:208,},
	'54s': {0:4,1:2,2:18,3:161,4:252,5:0,6:264,7:396,9:2145,10:1755,11:126,12:5508,13:168,14:0,},
	'54o': {0:0,1:2,2:18,3:0,4:256,5:0,6:264,7:396,9:440,10:1776,11:128,12:5508,13:168,14:0,},
	'53s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1233,11:126,12:5574,13:102,14:0,},
	'53o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1248,11:128,12:5574,13:102,14:0,},
	'52s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:711,11:63,12:5592,13:84,14:0,},
	'52o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:720,11:64,12:5592,13:84,14:0,},
	'44': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:192,11:0,12:17200,13:0,14:48,},
	'43s': {0:3,1:2,2:18,3:162,4:189,5:0,6:264,7:396,9:2145,10:1170,11:63,12:5640,13:36,14:0,},
	'43o': {0:0,1:2,2:18,3:0,4:192,5:0,6:264,7:396,9:440,10:1184,11:64,12:5640,13:36,14:0,},
	'42s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:648,11:63,12:5658,13:18,14:0,},
	'42o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:656,11:64,12:5658,13:18,14:0,},
	'33': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:128,11:0,12:17248,13:0,14:0,},
	'32s': {0:2,1:2,2:18,3:163,4:126,5:0,6:264,7:396,9:2145,10:585,11:0,12:5676,13:0,14:0,},
	'32o': {0:0,1:2,2:18,3:0,4:128,5:0,6:264,7:396,9:440,10:592,11:0,12:5676,13:0,14:0,},
	'22': {0:0,1:48,2:192,3:0,4:0,5:2112,6:0,7:0,9:440,10:64,11:0,12:17248,13:0,14:0,},
	}
#************************************************************************************
#
#************************************************************************************
def evalHandRange(handRange):
	"""evaluates a hand range against all possible flops"""
	noFlops = 0.0
	result = dict([(handName, 0) for handName in HandNames])
	for hand in handRange:
		handType = PokerTools.handTypeFromHand(hand)
		data = HandTypeData[handType]
		for handNameId, n in data.items():
			result[HandNameIds[handNameId]] += n
		noFlops += NoFlops
	for handName, n in result.items():
		result[handName] = n / noFlops
	return result
		
def evalHandN(holeCards, board):
	"""evaluates hole cards vs a specified flop"""
	data = dict([(i, 0) for i in HandNames.values()])
	hand = holeCards + board
	if handEval.getStraightFlush(hand):
		data[HandNames['StraightFlush']] += 1
		return data
	if handEval.getQuads(hand):
		data[HandNames['Quads']] += 1
		return data
	
	# could filter out flop is set and rank as OverPair/Pair, but nondense imo
	if handEval.getFullHouse(hand):
		data[HandNames['FullHouse']] += 1
		return data
					
	if handEval.getFlush(hand):
		data[HandNames['Flush']] += 1
		return data
	
	if handEval.getFlushDraw(hand):
		data[HandNames['FlushDraw']] += 1
		##return data
					
	if handEval.getStraight(hand):
		data[HandNames['Straight']] += 1
		return data
	
	if handEval.getOutsideStraightDraw(hand):
		data[HandNames['StraightDraw']] += 1
		##return data
	
	if handEval.getInsideStraightDraw(hand):
		data[HandNames['InsideStraightDraw']] += 1
		##return data
	
	# have to filter trips vs set
	result = handEval.getTrips(hand)
	if result:
		n = len([i for i in result[:3] if i in board])
		if n == 1:
			data[HandNames['Set']] += 1
			return data
		elif n == 2:
			data[HandNames['Trips']] += 1
			return data
		return data
			
	# filter out paired boards, we rank this as pair
	result = handEval.getTwoPair(hand)
	if result:
		n1 = len([i for i in result[:2] if i in board])
		n2 = len([i for i in result[2:4] if i in board])
		if n1 == n2 == 2:
			# board is double paired, ignore
			return data
		elif n1 == 0:
			# we hold a pocket pair
			maxBoard = max([i.rank() for i in board if i.rank() != result[0].rank()])
			if result[0].rank() > maxBoard:
				data[HandNames['OverPair']] += 1
			else:
				data[HandNames['Pair']] += 1
			return data
		elif n2 == 0:
			# we hold a pocket pair
			data[HandNames['Pair']] += 1
			return data
		elif n1 == n2 == 1:
			data[HandNames['TwoPair']] += 1
			return data
		elif n1 == 1 and n2 == 2:
			data[HandNames['TopPair']] += 1
			return data
		else:
			data[HandNames['Pair']] += 1
			return data
								
	# have to filter out paired boards
	result = handEval.getPair(hand)
	if result:
		n = len([i for i in result[:2] if i in board])
		if n == 2:
			return data
		elif n == 0:
			if result[0].rank() > result[2].rank():
				data[HandNames['OverPair']] += 1
			else:
				data[HandNames['Pair']] += 1
			return data
		##n == 1:
		maxBoard = max([i.rank() for i in board if i.rank() != result[0].rank()])
		if result[0].rank() > maxBoard:
			data[HandNames['TopPair']] += 1
			return data
		else:
			data[HandNames['Pair']] += 1
			return data
			
	return data

def evalBoard(handRange, board):
	"""evaluates a hand range vs a specified flop"""
	data = dict([(i, 0) for i in HandNames.values()])
	noFlops = 0.0
	for hand in handRange:
		if [i for i in hand.cards if i in board]:
			continue
		for handNameId, n in evalHandN(list(hand.cards), board).items():
			data[handNameId] += n
		noFlops += 1
	result = {}
	for handNameId, n in data.items():
		result[HandNameIds[handNameId]] = n / noFlops
	return result

def genHandTypeData():
	"""
	brute forces flop props of all hand types and prints result as dict to stdout
	WARNING: takes a couple of minutes to complete (~12mins on a reasonably fast machine)
	"""
	deck = PokerTools.CardDeck().cards
	handTypes = PokerTools.genHandTypes()
	print 'HandTypeData = {'
	for handType in handTypes:
		data = dict([(i, 0) for i in HandNames.values()])
		for board in itertools.combinations(deck, 3):
			holeCards = PokerTools.handTypeToHands(handType)[0].cards
			if holeCards[0] in board or holeCards[1] in board:
				continue
			for handNameId, n in evalHandN(holeCards, board).items():
				data[handNameId] += n
		print "\t'%s': {%s}," % (handType, ','.join(['%s:%s' % i for i in sorted(data.items())]))
	print '\t}'		

#************************************************************************************
#
#************************************************************************************	
def straightsFromHandType(handType):
	"""generates all straight types a handType can flop
	@param handType: (str)
	@return: (list) containing all straight types
	"""
	# determine card ranks. special case Ace low
	if PokerTools.handTypeIsPair(handType):
		return []
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	rank3 = None
	if rank1 == 12:
		rank3 = -1
	# iterate over all straight cadidates
	result = []
	for high in range(12, 2, -1):
		rng = range(high, high-5, -1)
		if rank2 in rng:
			if rank1 in rng:
				result.append([PokerTools.Card.RankNames[i] for i in rng])
			elif rank3 in rng:
				rng[-1] = 12
				result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result
	
def straightsFromHandTypeFormatted(handType):
	"""generates all straight types a handType can flop
	@param handType: (str)
	@return: (list) containing all straight types nicely formatted
	"""
	rank1 = handType[0]
	rank2 = handType[1]
	result = []
	for p in straightsFromHandType(handType):
		i = p.index(rank1)
		p[i] = '(%s)' % rank1
		if rank2 != rank1:
			i = p.index(rank2)
			p[i] = '(%s)' % rank2
		result.append(' '.join(p))
	return result
		
def outsideStraightDrawsFromHandType(handType):
	"""generates all outside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all outside straight draw types
	"""
	# determine card ranks. special case Ace
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	if rank1 == 12:
		return []
	ranks = (rank1, rank2)
		
	# iterate over all straight draw cadidates
	result = []
	for high in range(12, 3, -1):
		rng = range(high, high-6, -1)
		# if one of the cards is an edge card we do not have a straight draw 
		if rng[0] in ranks or rng[-1] in ranks:
			continue
			
		if rank1 in rng and rank2 in rng:
			rng = rng[1:-1]
			result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result

def outsideStraightDrawsFromHandTypeFormatted(handType):
	"""generates all outside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all outside straight draw types nicely formatted
	"""
	rank1 = handType[0]
	rank2 = handType[1]
	result = []
	for p in outsideStraightDrawsFromHandType(handType):
		i = p.index(rank1)
		p[i] = '(%s)' % rank1
		if rank2 != rank1:
			i = p.index(rank2)
			p[i] = '(%s)' % rank2
		p.insert(0, '_')
		p.append('_')
		result.append(' '.join(p))
	return result
		
def insideStraightDrawsFromHandType(handType):
	"""generates all inside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all inside straight draw types
	"""
	# determine card ranks. special case Ace low
	if PokerTools.handTypeIsPair(handType):
		return []
	rank1, rank2 = PokerTools.handTypeRanks(handType)
	rank3 = None
	if rank1 == 12:
		rank3 = -1
	# iterate over all inside straight draw candidates
	# 9 x 8 7 6 x 4
	result = []
	for high in range(12, 4, -1):
		rng = range(high, high-7, -1)
		rng[1] = 'x'
		rng[-2] = 'x'
		if rank2 in rng:
			if rank1 in rng:
				rng.pop(1)
				rng.pop(-2)
				result.append([PokerTools.Card.RankNames[i] for i in rng])
			elif rank3 in rng:
				rng[-1] = 12
				rng.pop(1)
				rng.pop(-2)
				result.append([PokerTools.Card.RankNames[i] for i in rng])
	return result
	
def insideStraightDrawsFromHandTypeFormatted(handType):
	"""generates all inside straight draw types a handType can flop
	@param handType: (str)
	@return: (list) containing all inside straight draw types nicely formatted
	"""
	rank1 = handType[0]
	rank2 = handType[1]
	result = []
	for p in insideStraightDrawsFromHandType(handType):
		i = p.index(rank1)
		p[i] = '(%s)' % rank1
		if rank2 != rank1:
			i = p.index(rank2)
			p[i] = '(%s)' % rank2
		p.insert(1, '_')
		p.insert(-1, '_')
		result.append(' '.join(p))
	return result				

#************************************************************************************
#
#************************************************************************************		
if __name__ == '__main__':
	genHandTypeData()
	pass		
			
			
